<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>教练分配</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="../../static/css/style.css"  media="all">
    <script type="text/javascript" src="../../static/js/jquery.min.js" ></script>
    <script src="../../layui/layui.js" charset="utf-8"></script>
    <script src="../../static/js/base.js" charset="utf-8"></script>
    <script src="../../static/js/ax.js"></script>
    <script src="../../static/js/jquery.cookie.js"></script>
    <script src="js/constant.js"></script>
    <script src="../../static/js/avalon.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="../../static/js/html5.js"></script>
    <script src="../../static/js/respond.js"></script>
    <![endif]-->
</head>
<body class="bg_w">

<div class="content-wrap" ms-controller="test">

    <div class="layui-row">
        <form class="layui-form layui-form-pane" id="from1">
            <input type="hidden" id="dataId" value="" />
            <div class="layui-row layui-form-item layui-col-space15">
                <div class="layui-col-sm5">
                    <label class="layui-form-label">学员信息：</label>
                    <div class="layui-input-block">
                        <input type="text" id="nameOrNum"  class="layui-input"  maxlength="100" placeholder="请输入姓名和证件号码">
                    </div>
                </div>
                <div class="layui-col-sm5">
                    <label class="layui-form-label">准驾车型：</label>
                    <div class="layui-input-block">
                        <select id="carId">

                        </select>
                    </div>
                </div>
                <div class="layui-col-sm5">
                    <label class="layui-form-label">考试时间：</label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input" id="timeStart" autocomplete="off">
                    </div>
                </div>
                <div class="layui-col-sm5 selectButton">

                        <button  type="button"  class="layui-btn add_btn" data-type="reload"><i class="layui-icon layui-icon-search"></i>搜索</button>
                        <button type="button" type="reset" class="layui-btn layui-btn-primary" data-type="reloadClean">重置</button>


                </div>
                <div class="layui-col-sm5">
                    <label class="layui-form-label">所属教练：</label>
                    <div class="layui-input-block" id="dsName">
                        <input type="hidden" id="coachId" :duplex="@coachId" >
                        <input type="text" class="layui-input" :duplex="@coachname" id="coach" :focus="coachselect()">
                    </div>
                </div>
                <div class="layui-col-sm5">
                    <button type="button" class="layui-btn add_btn" :click="coachselect()">搜索</button>
                    <button type="button" class="layui-btn change_btn" :click="checkAll()">全选</button>
                    <button type="button" class="layui-btn delete_btn" :click="checkAllno()">取消全选</button>
                </div>
            </div>
            <input type="hidden" id="classname" ms-duplex="@classname">
            <input type="hidden" id="caochdata" ms-duplex="@caochdata">

            <div class="layui-form-item">

                <table class="layui-hide" id="listTbale"
                       lay-filter=""></table>

                <div class="layui-input-block">
                    <button type="button" id="btnClose" class="layui-btn layui-btn-primary btn-left">关闭</button>
                    <button type="button" id="btnSubmit" class="layui-btn add_btn btn-left" lay-submit lay-filter="component-form-element">提交</button>
                </div>
            </div>

        </form>
    </div>
</div>

</body>

<script>
    var orgList = [];
    var $;
    var layedit;
    var baseData=null;
    var layer;
    var data=getQueryString("class");
    var table;
    var form;
    console.log(data)
   var vm = avalon.define({
        $id: "test",
        studentlist:[],
        classname:'',
        address:false,
        addressactive:'',
        studentid:[],
        examTime:'',
        stuid:[],
       coachId:'',
       caochdata:'',
       coachname:'',
       //选择教练
       coachselect:function(){
           layer.open({
               type: 2,
               title:'选择教练',
               area: ['90%', '80%'],
               fixed: true, //不固定
               maxmin: true,
               content: 'coachChoice.html'
           });
       },

        GetValue: function(){
           var coach=JSON.parse(vm.caochdata)

           vm.coachname=coach.name
            vm.coachId=coach.id;

        },
        //地址搜索
        addresssearch:function () {
            vm.address=true;
            setTimeout(function () {
                form.render('select')
            },200)

        },
        //学员删除
        removestydent: function (index) {
            console.log(index)
            vm.studentlist.removeAt(index);
            vm.stuid.removeAt(index);
        },
       // 全选
       checkAll: function () {
           var checkStatus = table.checkStatus('testReload');
           if (checkStatus.isAll == true) {
               return;
           }
           $('.layui-form-checkbox').click();
           form.render('checkbox');
           console.log(checkStatus)
       },
       // 反选
       checkAllno: function () {
           var checkStatus = table.checkStatus('testReload');
           if (checkStatus.isAll == false) {
               return;
           }
           $('.layui-form-checkbox').click();
           form.render('checkbox');
       },
    });
    vm.$watch('onReady', function () {
        if(data==1){
            vm.classname='k1';
        }
        if(data==2){
            vm.classname='k2';
        }
        if(data==3){
            vm.classname='k3';
        }
        if(data==4){
            vm.classname='k4';
        }


    });
    vm.$watch('caochdata', function () {
        console.log('123');
        console.log(JSON.parse(vm.caochdata))
        vm.GetValue();
    });

    layui.use(['layedit','form','laydate','layer','table'], function() {
        $ = layui.$;
        layer=layui.layer;
        table = layui.table;
        layedit = layui.layedit;
        form = layui.form;
        var layDateTipsStartTime = layui.laydate,
            layDateTipsEndTime = layui.laydate;



        // 初始化日期控件
        layDateTipsStartTime.render({
            elem: '#timeStart',
        });

        //关闭弹窗
        $('#btnClose').on("click", function () {
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        });

        var initBaseData = function () {
            ax.get({
                url: schoolWebUrl+"/api/student/getBaseData",
                success: function (res) {
                    if (res.code == 0) {
                        baseData=res.data;
                        loadBaseData();
                    } else {
                        layer.msg(res.message);
                    }
                }

            });
        };
        var loadBaseData = function () {
            // 初始  证件
            // $("#sfType").empty();
            // $("#sfType").append("<option value=''>请选择</option>");
            // $.each(baseData.zjTypeList, function (index, zj) {
            //     $("#sfType").append("<option value='" + zj.id + "'>" + zj.code + "</option>");
            // });

            // 准驾车型列表
            $("#carId").empty();
            $("#carId").append("<option value=''>请选择</option>");
            $.each(baseData.carTypeList, function (index, carType) {
                $("#carId").append("<option value='" + carType.id + "'>" + carType.code + "</option>");
            });
            form.render('select');

        };
        initBaseData();
         console.log(vm.classname)

        var tableIns = ax.VTable({
            elem : '#listTbale',
            url : schoolWebUrl+'/api/coachStudent/queryStudentCoach?subject='+data+'&status='+data,
            id: 'testReload',
            title:'学员列表',
            cols : [ [
                {type : 'checkbox'},
                {field : 'id', width : 80, title : '序号',type:'numbers'},
                {field : 'driverName', minWidth : 150, title : '报名机构', sort : true},
                {field : 'studentNumber', title : '学员编号', minWidth : 150},
                {field : 'studentName', minWidth : 120, title : '姓名', sort : true},
                {field : 'certificatesNumber', minWidth : 150, title : '证件号码', sort : true},
                {field : 'sfTypeName', width : 150, title : '证件类型'},
                {field : 'carName', width : 150, title : '准驾车型'},
                {field : 'examTime', width : 150, title : '上科考试时间'},
                //{field : 'examSubject', width : 150, title : '约考科目'},
                //  {field : 'examAddress', width : 150, title : '考试地点'},
                {field : 'degree', width : 150, title : '考试次数'},
                // {field : 'examField', width : 150, title : '是否合格'},
                // {field : 'examTime', width : 150, title : '考试时间'},
            ] ]

        });
        student = {
            reload : function() {
                initTable();
            },
            reloadClean:function()
            {
                emptyTable();
            }
        };
        $('.selectButton .layui-btn').on('click', function(){
            var type = $(this).data('type');//获取reload
            student[type] ? student[type].call(this) : '';
        });


        var initTable=function (data) {
            table.reload('testReload', {
                page : {
                    curr: 1 //重新从第 1 页开始
                },
                where : {
                    nameOrNum : $('#nameOrNum').val(),
                    carId : $('#carId').val(),
                    timeStart : $('#timeStart').val(),
                }
            });
        }

        var emptyTable=function () {
            $('#nameOrNum').val("");
            $('#carId').val('');
            $('#timeStart').val("");
            form.render('select');//重新加载select
            table.reload('testReload');
        }

        form.on('submit(component-form-element)', function(data){
            var checkStatus = table.checkStatus('testReload').data;
            if(vm.coachId==''){
                layer.msg('请选择教练')
            }else {
                if(checkStatus.length==0){
                    layer.msg('请选择学员')
                } else {
                    var ss=[];
                    for(var s in checkStatus){
                        var list={"studentId":checkStatus[s].studentId,"subject":vm.classname,"coachId":vm.coachId}
                        ss.push(list)
                    }

                    console.log(JSON.stringify(ss))
                    ax.post({
                        url: schoolWebUrl + "/api/coachStudent/add",
                        data: JSON.stringify(ss),
                        success: function (data) {
                            // layer.msg(data.message);
                            if (data.code == 0) {
                                layer.msg('教练分配成功')
                                //刷新父页面
                                topFrame.location.reload();
                                setTimeout(function () {
                                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                                },300)

                            } else {
                                layer.msg('教练分配失败')
                            }
                        }
                    });
                }
            }



            return false;

        });


//得到子窗口的参数
//         function GetValue(data){
//             $("#coach").val(data.name);
//             $("#coachId").val(data.id);
//             vm.coachId=data.id;
//         }

    });







</script>
</html>